package main.java.com.yc.navy.snacknet.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yc.navy.snacknet.bean.ProductInfo;
import com.yc.navy.snacknet.mapper.IProductinfoMapper;
import com.yc.navy.snacknet.service.IProductinfoService;
import com.yc.navy.snacknet.util.FindByPageParamUtil;
import com.yc.navy.snacknet.util.StringUtil;

@Service
public class ProductinfoServiceImpl implements IProductinfoService{
	
	@Autowired
	private IProductinfoMapper productinfoMapper;

	@Override
	public List<ProductInfo> finds(Map<String, Object> map) {
		return productinfoMapper.finds(FindByPageParamUtil.findByPage(map));
	}

	@Override
	public Map<String, Object> findByFirst(Map<String, Object> map) {
		Map<String, Object> result = new HashMap<String, Object>();
		List<ProductInfo> list = this.finds(map);
		if(list == null || list.isEmpty()) {
			return null;
		}
		result.put("data", list);
		result.put("total", productinfoMapper.total(map));
		return result;
	}

	@Override
	public int add(ProductInfo pf) {
		if(StringUtil.checkNull(pf.getPname(), pf.getPics(), pf.getPrice())) {
			return -100;
		}
		return productinfoMapper.add(pf);
	}
	
	@Override
	public ProductInfo findByPno(String pno) {
		if(StringUtil.checkNull(pno)) {
			return null;
		}
		return productinfoMapper.findByPno(pno);
	}
}
